import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

/**
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 *
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: ''                     the icon show in the sidebar. see: https://iconmonstr.com/iconicfont/
    affix: true                  if set true, the tag will affix in the tags-view
    tagGroup: false
    tagTitle: ''
  }
 */

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import(/* webpackChunkName: "Redirect" */ '@/views/Redirect')
      }
    ]
  },
  {
    path: '/401',
    component: () => import(/* webpackChunkName: "401" */ '@/views/Error/401'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "404" */ '@/views/Error/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: 'Dashboard',
    children: [
      {
        path: 'Dashboard',
        component: () => import(/* webpackChunkName: "Dashboard" */ '@/views/Dashboard'),
        name: 'Dashboard',
        meta: { title: '主页', icon: 'im im-home', affix: true }
      }
    ]
  }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
